#include "Crate.h"
#include "Camera.h"
#include "GameplayState.h"
#include "../SGD Wrappers/SGD_AudioManager.h"

Crate::Crate()
{
	SGD::GraphicsManager * pGraphics = SGD::GraphicsManager::GetInstance();

	m_hImage = pGraphics->LoadTexture("resource/graphics/Crate_old.png");
	m_aAudio = SGD::AudioManager::GetInstance()->LoadAudio("resource/audio/Box Breaking 3.wav");
}


Crate::~Crate()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(m_hImage);
	SGD::AudioManager::GetInstance()->UnloadAudio(m_aAudio);

}

void Crate::Update(float dt)
{
	if (m_bWasTriggered)
		m_vtParticle[0]->Update(dt);
}

void Crate::Render()
{
	SGD::GraphicsManager* pGraphics = SGD::GraphicsManager::GetInstance();

	//SGD::Rectangle crate = SGD::Rectangle{0, 0, 128, 128};
	if (m_bAlive)
	pGraphics->DrawTexture(
		m_hImage, 
		{
		m_ptPosition.x - GameplayState::GetInstance()->GetCamX(), 
		m_ptPosition.y - GameplayState::GetInstance()->GetCamY()
		});

	if (m_bWasTriggered)
		m_vtParticle[0]->Render();

}



void Crate::HandleCollision(BaseObject* pOther)
{
	if (!m_bAlive)
		SGD::AudioManager::GetInstance()->PlayAudio(m_aAudio);
}